<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>obkengine v0.1 alpha</title>
    <script src="jquery.min.js"></script>
    <!-- <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">    </script> -->
    <script src="preload.js"></script>
    <script src="module/macro.js"></script>
    <script src="module/label.js"></script>
    <script src="phaser.min.js"></script>
</head>

<body>
    <h1 id="loading">loading... please click to start</h1>
    <!--  <script>
        //phaser预加载太耗费时间，需要开多线程
        /*首先，先运行jquery ajax， 异步获得源代码，处理完了之后再回调给back函数 再启动phaser*/
        $(function() {
                if (obk_state == "init") {
                    obk_url = "bke_src/main.bkscr"
                }
            })
            //init phaser
            //pharser3.55.2
        var config = {
            type: Phaser.AUTO,
            width: 800,
            height: 600,
            scene: {
                preload: preload,
                jump_callback,
                create: create, //场景
            }
        }
        var game = new Phaser.Game(config)
        var my_phaser
        var cursors
        var obk_logo
        var obk_imgs = []
            //phaser中的对象
        var display_text
        var obk_basic_layer
        var obk_msg_layer
        var obk_text_layer
        var obk_home

        function preload() {

            if (obk_state == "init") {
                my_phaser = this
                this.load.audio("loading", "qmxz.mp3")
                this.load.image("obk", "obkengine.png")
                obk_basic_layer = this.add.layer()
                obk_text_layer = this.add.layer()
                    // console.log(obk_logo)
            }
            if (obk_state == "jump") {
                this.load.image("home", obk_imgs[0])
                    //                obk_home = this.load.image("home", obk_imgs[0])
                    //  this.load.audio("f", "bke_src/fsl.mp3")
            }
        }

        function create() {
            display_text = this.add.text(0, 0, "null").setStyle(obk_text_style)
            display_text.setDepth(1)
                //全局鼠标事件
            this.input.on('pointerdown', function(pointer) {
                //去除[p]
                obk_text = obk_texts[obk_clicks] //.replace(/\[|]|p/g, "")
                obk_clicks += 1
                if (obk_text != null) {

                    console.log('down' + obk_clicks)
                    console.log(obk_text)
                    display_text.setText(obk_text)
                    console.log("按下了鼠标")
                } else {
                    console.error("执行到文字末尾")
                }

            }, this);
            if (obk_state == "init") {
                obk_logo = this.add.image(0, 0, "obk").setOrigin(0, 0)
                var music = this.sound.add("loading")
                music.on("complete", function() {
                    console.log("完成音乐播放，加载游戏")
                    obk_logo.setAlpha(0.5)
                    obk_logo.destroy()
                    $._get_data(back)
                })
                music.play()
            }
            if (obk_state == "jump") {
                this.add.image(400, 300, "home")
            }
        }

        function update() {}
        //每次get之后的回调函数 ajax异步
        function back(rs) {
            //每次get之后的回调
            // obk_state = "back_1"
            console.log("回调结果")
            console.log(rs)
            if (rs[0][0] == "@jump") {
                console.log("@jump " + rs[0][1])
                    //跳转到下一个场景
                var jump_file = "bke_src/" + rs[0][1]
                obk_url = jump_file
                    //jump事件回调
                $._get_data(jump_callback)
            }
        }

        function jump_callback(rs) {
            console.log("jump事件回调")
            console.log(rs)
            obk_state = "jump"
            var tmp_img = "bke_src/" + rs[1][2]
            console.log(tmp_img)
            obk_imgs.push(tmp_img)
            console.log("回调文字")
            console.log(obk_texts)
            my_phaser.scene.start()
        }
        /*for (var i = 0; i < rs.length; i++) {
                var tmp = rs[i]
                if (tmp.length > 1) {
                    var cmd = tmp[0]
                    var file = "bke_src/" + tmp[1]
                    obk_bg = str_utils(file)
                    console.log(obk_bg)
                    my_phaser.load.image("home", obk_bg)
                    my_phaser.add.image(400, 300, "home")
                }
            }
            obk_state = "change_scene"
        }*/
    </script>-->
</body>

</html>